package com.llb666.e.shop.domain.entity;

import com.llb666.e.shop.domain.entity.bo.SubmitOrderBo;
import com.llb666.e.shop.infracore.enums.YesOrNo;
import lombok.Data;

import java.util.Date;

/**
 * @author llb666
 */
@Data
public class Orders {
    /**
     * 订单主键;同时也是订单编号
     */
    private String id;

    /**
     * 用户id
     */
    private String userId;

    /**
     * 收货人快照
     */
    private String receiverName;

    /**
     * 收货人手机号快照
     */
    private String receiverMobile;

    /**
     * 收货地址快照
     */
    private String receiverAddress;

    /**
     * 订单总价格
     */
    private Integer totalAmount;

    /**
     * 实际支付总价格
     */
    private Integer realPayAmount;

    /**
     * 邮费;默认可以为零，代表包邮
     */
    private Integer postAmount;

    /**
     * 支付方式
     */
    private Integer payMethod;

    /**
     * 买家留言
     */
    private String leftMsg;

    /**
     * 扩展字段
     */
    private String extand;

    /**
     * 买家是否评价;1：已评价，0：未评价
     */
    private Integer isComment;

    /**
     * 逻辑删除状态;1: 删除 0:未删除
     */
    private Integer isDelete;

    /**
     * 创建时间（成交时间）
     */
    private Date createdTime;

    /**
     * 更新时间
     */
    private Date updatedTime;


    /**
     * 下单时封装下单需要的do
     *
     * @param orderId       订单Id
     * @param submitOrderBo 提交的订单信息.
     * @param userAddress   用户的收获地址信息.
     * @return 订单
     */
    public static Orders createDo(String orderId, SubmitOrderBo submitOrderBo, UserAddress userAddress) {
        Orders order = new Orders();
        order.setId(orderId);
        order.setUserId(submitOrderBo.getUserId());
        order.setLeftMsg(submitOrderBo.getLeftMsg());
        order.setPayMethod(submitOrderBo.getPayMethod());
        order.setIsComment(YesOrNo.NO.type);
        order.setIsDelete(YesOrNo.NO.type);
        order.setCreatedTime(new Date());
        order.setUpdatedTime(new Date());
        order.setReceiverName(userAddress.getReceiver());
        order.setReceiverMobile(userAddress.getMobile());
        order.setReceiverAddress(userAddress.getProvince() + "" + userAddress.getCity() + ""
                + userAddress.getDistrict() + "" + userAddress.getDetail() + "");
        return order;
    }
}